<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>玩家管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<!-- 自动查找引入进来的工具类脚本。 -->
	<link rel="stylesheet" href="./layui/css/layui.css"  media="all">
</head>
<body>
<!-- 抬头 -->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>玩家管理</legend>
</fieldset>
<!-- 跳转工具栏 -->
<ul class="layui-nav">
<li class="layui-nav-item" lay-unselect="">
	<label class="layui-form-label" style="padding:7.5px 0px;">当前管理员</label>
	<label class="layui-form-label" id='CURID' style="padding:7.5px 0px;"></label>
</li>
<li class="layui-nav-item" lay-unselect="">
		<a href="javascript:void(0)" onclick="gotoGlubManager();" target='topFrame'>[转到公会管理]</a>
</li>
</ul>

<!-- 搜索栏 -->
<form onsubmit="return false;" class="layui-form layui-form-pane" action="" lay-filter="example">
	<!-- 搜索栏内容 -->
	<div class="layui-form-item">
	<label class="layui-form-label">用户id</label>
	<div class="layui-input-inline">
		<input type="text" name="userID" lay-verify="required" autocomplete="off" class="layui-input"
		onkeyup="value=value.replace(/[^0-9-]+/,'');"
		oninput="if(value.length>6)value=value.slice(0,6)">
	</div>
    <div class="layui-form-mid layui-word-aux">请输入玩家6位帐号ID进行搜索</div>
	</div>
	
	<!-- 提交搜索 -->
	<div class="layui-form-item">
	<div class="layui-input-block">
		<button class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
	</div>
	</div>
</form>
<!-- 分割线 -->
<hr class="layui-bg-orange">
<!-- 表格显示栏 -->
<table class="layui-hide" id="user_data" lay-filter="user_data"></table>

<!-- 自动查找引入进来的工具类脚本。 -->
<script src="./layui/layui.js" charset="utf-8"></script>

<script>
layui.config({
	version: true
}).use(['form','layer','jquery','table','mobile'], function(){
	var ws = new WebSocket("ws://192.168.1.116:8080");
	// 连接成功
	ws.onopen = function (e) {
		console.log('连接成功获取到的上半段脚本定义的用户id和客服id=',selfid);
		ws.send(JSON.stringify({
			type: 'REGISTER', 	// 随便定义，用于在服务端区分消息类型
			selfid: selfid,		// 写入自身id
		})); 
	}
	// 连接关闭
	// ws.onclose = function (e) {
	// 	console.log('连接关闭');
	// }
	var mobile = layui.mobile,
		form = layui.form,
        layer = layui.layer,
		form = layui.form,
		table = layui.table,
		$= layui.jquery;


	document.getElementById('CURID').innerHTML = selfid;
	// 监听搜索按钮
    form.on('submit(search)', function(data){
		console.log("返回的结果是啥啊",data.field,data.field.userID);
		$.post("/user_data",data.field,function(result){
            if(result.status == "fail"){
                layer.alert(JSON.stringify(result.msg),{
					skin: 'layui-layer-molv',
					closeBtn: 0
				},function(){
                    window.parent.location.reload();    // 刷新父类页面
                    parent.layer.close(index);          // 关闭当前的弹窗
                });
                console.log("搜索失败",result);
            }else {
				console.log("搜索成功",result.user_data);
				table.render({
					elem: '#user_data',
					title: '玩家信息',
					cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
					cols: [[
						{field:'userid', width:80, title: '玩家ID', align: 'center'},
						{field:'username', width:80, title: '玩家名称', align: 'center'},
						{field:'money', width:80, title: '金币', align: 'center',edit: 'text'},
						{field:'diamonds', width:80, title: '钻石', align: 'center',edit: 'text'},
					]],
					data: result.user_data,		// 数据赋值
				});
            }
        })
        return false;
	});
	
	//监听单元格编辑
	table.on('edit(user_data)', function(obj){
		var value = obj.value, //得到修改后的值
			data = obj.data, //得到所在行所有键值
			field = obj.field;//得到字段
		layer.msg('[userid: '+ data.userid +'] ' + field + ' 字段更改为：'+ value);
	});
});
function gotoGlubManager(){
	console.log('打开公会管理');
	location.href="/?val=clubManager&selfid="+selfid;
};
</script>
</body>
</html>
